﻿Imports System.Collections.ObjectModel
Imports TwitterVB
Imports System.ComponentModel
Imports System.Windows.Threading
Public Class twits
    Inherits ObservableCollection(Of twit)
    Private dispatcherUIThread As Dispatcher

    Private Delegate Sub SetItemCallback(ByVal index As Integer, ByVal item As twit)
    Private Delegate Sub RemoveItemCallback(ByVal index As Integer)
    Private Delegate Sub ClearItemsCallback()
    Private Delegate Sub InsertItemCallback(ByVal index As Integer, ByVal item As twit)
    Private Delegate Sub MoveItemCallback(ByVal oldIndex As Integer, ByVal newIndex As Integer)

    Public Sub New(ByVal dispatcher As Dispatcher)
        Me.dispatcherUIThread = dispatcher
    End Sub

    Protected Overloads Overrides Sub SetItem(ByVal index As Integer, ByVal item As twit)
        If dispatcherUIThread.CheckAccess() Then
            MyBase.SetItem(index, item)
        Else
            dispatcherUIThread.Invoke(DispatcherPriority.Send, New SetItemCallback(AddressOf SetItem), index, New Object() {item})
        End If
    End Sub

    Protected Overloads Overrides Sub RemoveItem(ByVal index As Integer)
        If dispatcherUIThread.CheckAccess() Then
            MyBase.RemoveItem(index)
        Else
            dispatcherUIThread.Invoke(DispatcherPriority.Send, New RemoveItemCallback(AddressOf RemoveItem), index)
        End If
    End Sub

    Protected Overloads Overrides Sub ClearItems()
        If dispatcherUIThread.CheckAccess() Then
            MyBase.ClearItems()
        Else
            dispatcherUIThread.Invoke(DispatcherPriority.Send, New ClearItemsCallback(AddressOf ClearItems))
        End If
    End Sub

    Protected Overloads Overrides Sub InsertItem(ByVal index As Integer, ByVal item As twit)
        If dispatcherUIThread.CheckAccess() Then
            MyBase.InsertItem(index, item)
        Else
            dispatcherUIThread.Invoke(DispatcherPriority.Send, New InsertItemCallback(AddressOf InsertItem), index, New Object() {item})
        End If
    End Sub

    Protected Overloads Overrides Sub MoveItem(ByVal oldIndex As Integer, ByVal newIndex As Integer)
        If dispatcherUIThread.CheckAccess() Then
            MyBase.MoveItem(oldIndex, newIndex)
        Else
            dispatcherUIThread.Invoke(DispatcherPriority.Send, New MoveItemCallback(AddressOf MoveItem), oldIndex, New Object() {newIndex})
        End If
    End Sub

End Class

Public Class twit
    Implements INotifyPropertyChanged

    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

    Private Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    ' Fields
    Private _id As Long
    Private _resim As String
    Private _txt As String

    ' Methods
    Public Sub New(ByVal id As Long, ByVal resim As String, ByVal txt As String)
        _id = id
        _resim = resim
        _txt = txt
    End Sub

    ' Properties
    Public Property id() As Long
        Get
            Return _id
        End Get
        Set(ByVal value As Long)
            _id = value
            OnPropertyChanged("id")
        End Set
    End Property

    Public Property resim() As String
        Get
            Return _resim
        End Get
        Set(ByVal value As String)
            _resim = value
            OnPropertyChanged("resim")
        End Set
    End Property

    Public Property txt() As String
        Get
            Return _txt
        End Get
        Set(ByVal value As String)
            _txt = value
            OnPropertyChanged("txt")
        End Set
    End Property
End Class

Public Class bilgiler
    Implements INotifyPropertyChanged

    Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

    Private Sub OnPropertyChanged(ByVal propertyName As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
    End Sub

    ' Fields
    Private _calisiyor As Boolean

    ' Properties
    Public Property calisiyor() As Boolean
        Get
            Return _calisiyor
        End Get
        Set(ByVal value As Boolean)
            _calisiyor = value
            OnPropertyChanged("calisiyor")
        End Set
    End Property
End Class
